package com.example.lib_network.repository

import com.example.lib_network.baseBean.BaseResponse
import com.example.lib_network.error.ApiException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import kotlinx.coroutines.withTimeout

/**
 *
 * @Description TODO
 * @Author Bohemian
 * @CreateTime 2024/01/19/ 20:28
 */
open class BaseRepository {
    suspend fun <T> requestResponse(requestCall: suspend ()->BaseResponse<T>?): T? {
        val response=withContext(Dispatchers.IO){
            withTimeout(10*1000){
                requestCall()
            }
        }?:return  null
        if(response.isFailed()){
            throw ApiException(response.erroCode,response.erroMsg)
        }
        return response.data
    }
}